import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 				= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
const $time 			= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '接收时间',		names: ['start_at','end_at'], 	type:'date-range', 	loading:true,	name:'jz-time', },
			{ label: '科室',			name: 'project_parent_id',		type: 'select', 	loading:true,	idStr:'uuid' },
			{ label: '岗位',			name: 'project_id',				type: 'select', 	loading:true },
			{ label: '自然项目',		name: 'parent_kind_id',			type: 'select', 	loading:true },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{
			const arr = f.duration['2']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 科室
			$fn.setRow(forms, 'project_parent_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow(forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			// 自然项目
			$fn.setRow(forms, 'parent_kind_id', await f.getCache({ api:'nature_project' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/parentKindCount', {isIndex:true})
	
	// 表单
	cols = [
		{ title: '科室', 		dataIndex: 'project_parent_name', 	width:150 },
		{ title: '岗位', 		dataIndex: 'project_name', 			width:150 },
		{ title: '自然项目', 	dataIndex: 'parent_kind_name', 		width:230 },
		{ title: '数量', 		dataIndex: 'count_total', 			width:100 },
	]
	
	render(){
		return (
			<Page title='自然项目数量统计'>
				{/* 搜索 */}
				{ SearchForm.call(this, {timeStr: '2'}) }
				{/* 表格 */}
				{ Table.call(this, {isInit: window.isInit, isIndex: true}) }
			</Page>
		)
	}
}

export default Index
 // 新增自然项目数量统计 2022-05-10  --马婷 